package speed.mvc.servlet;

/**
 * @author zhaohaolin(zhaohaolin2010@gmail.com)
 */
public class CharHelper {

	// 把单词第一个字母转换为大写
	public static String upperFirstWords(String source) {
		StringBuffer sb = new StringBuffer();
		char[] words = source.toCharArray();
		char prevc = ' ';
		for (char c : words) {
			if (c != ' ' && prevc == ' ') {
				sb.append(Character.toUpperCase(c));
			} else {
				sb.append(c);
			}
			prevc = c;
		}

		return sb.toString();
	}

	// 把单词第一字母转换为小写
	public static String lowerFirstWords(String source) {
		StringBuffer sb = new StringBuffer();
		char[] words = source.toCharArray();
		char prevc = ' ';
		for (char c : words) {
			if (c != ' ' && prevc == ' ') {
				sb.append(Character.toLowerCase(c));
			} else {
				sb.append(c);
			}
			prevc = c;
		}

		return sb.toString();
	}

	public static void main(String[] args) {
		String name = lowerFirstWords("HelloAction");
		System.out.println(name.replace("Action", ""));
	}

}
